package com.guldan.jaina.manager;

import com.guldan.core.exception.BusinessException;
import com.guldan.core.manager.BaseManager;
import com.guldan.core.redis.CacheService;
import com.guldan.mapper.db.entity.GRole;
import com.guldan.mapper.db.entity.RegisterSuccess;
import com.guldan.mapper.db.entity.RegisterSuccessExample;
import com.guldan.mapper.db.mapper.GRoleMapperExt;
import com.guldan.mapper.db.mapper.RegisterSuccessMapperExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Silas.
 * Date: 2016/12/17
 * Time: 15:41
 */
@Service
public class TestManager extends BaseManager {


    @Autowired
    private RegisterSuccessMapperExt registerSuccessMapperExt;

    @Autowired
    private CacheService cacheService;

    public String testExecption() throws BusinessException {

        throw new BusinessException("异常内容123");

    }


    @Resource
    private GRoleMapperExt gRoleMapperExt;


    //    @Transactional(value = "dbTransactionManager")
    public GRole insertGRoleTest(GRole gRole) {

        GRole gRole2 = new GRole();
        gRole2.setRoleName("tttt");
        gRole2.setRoleCode("xxxx");
        gRoleMapperExt.insertSelective(gRole2);

        gRoleMapperExt.insertSelective(gRole);
        return gRole;
    }

    public String bigObject(String summaryId) {

        RegisterSuccessExample example = new RegisterSuccessExample();
        RegisterSuccessExample.Criteria criteria = example.createCriteria();
        criteria.andSummaryIdEqualTo(summaryId);
        List<RegisterSuccess> list = registerSuccessMapperExt.selectByExample(example);

        long cost = System.currentTimeMillis();
        String key = "temp_data_" + summaryId;
        cacheService.putCache(key, list);
        cost = System.currentTimeMillis() - cost;
        logger.info("temp_data_" + summaryId + ", cost " + cost);

        return key;

    }


}
